Skip to content

[testutils] Optimize the runtime of the method verify_no_packet_any for large port sets#231

Open
AntonHryshchuk wants to merge 1 commit intop4lang:mainfrom
AntonHryshchuk:update_verify_no_packet_any
Open

[testutils] Optimize the runtime of the method verify_no_packet_any for large port sets#231
AntonHryshchuk wants to merge 1 commit intop4lang:mainfrom
AntonHryshchuk:update_verify_no_packet_any

Conversation

@AntonHryshchuk
Copy link

Optimize verify_no_packet_any method for large port sets

The original implementation waits for the full timeout on each port
sequentially, resulting in O(N * timeout) runtime (e.g. 500ports → 50 seconds, with 0.1 second of default timeout).

This change introduces a single global timeout and repeatedly polls all ports
using non-blocking dp_poll(timeout=0), ensuring:

  • correct negative-check semantics (packet must not appear during the interval)
  • full coverage of all ports passed explicitly
  • runtime bounded by the configured timeout

Also adds a small sleep to avoid busy looping and reduce CPU usage.

@AntonHryshchuk AntonHryshchuk force-pushed the update_verify_no_packet_any branch from 51712d8 to 6735621 Compare January 14, 2026 08:00
return True # PASS - packet not observed within timeout window

for port in ports:
result = dp_poll(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you still validate it port-by-port, and not in parallel unless I don't understand the code

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, the validation is still per port, but the key change is that the timeout is now global, not per-port.
Each port is polled in a non-blocking way into a loop bounded by a single timeout window.
It's not parallel, but it reduces the runtime from O(N × timeout) to O(timeout) and still detects packets on any port. Parallel way is not really possible here because the poll operates on a shared dataplane. Polling it from multiple threads not providing additional benefits and can lead to race conditions.

@AntonHryshchuk AntonHryshchuk force-pushed the update_verify_no_packet_any branch from 6735621 to 3d402ef Compare January 14, 2026 17:53


def verify_no_packet_any(test, pkt, ports=[], device_number=0, timeout=None):
def verify_no_packet_any(test, pkt, ports=[], device_number=0, timeout=1):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value of timeout was ptf.ptfutils.default_negative_timeout, we should keep it the same.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't be used with default_negative_timeout as before.
Now, it's a global timeout of the method.
Previously, it was the timeout for a single dp_poll call.
This value(0) is too small for the global timeout.

@fruffy fruffy requested a review from antoninbas January 17, 2026 08:46
@AntonHryshchuk AntonHryshchuk force-pushed the update_verify_no_packet_any branch from 6cd58b1 to d3d9b5d Compare January 18, 2026 10:47
… scale ports number

Signed-off-by: AntonHryshchuk <antonh@nvidia.com>
mssonicbld added a commit to mssonicbld/sonic-buildimage that referenced this pull request Feb 19, 2026
<!--
     Please make sure you've read and understood our contributing guidelines:
     https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md

     ** Make sure all your commits include a signature generated with `git commit -s` **

     If this is a bug fix, make sure your description includes "fixes #xxxx", or
     "closes #xxxx" or "resolves #xxxx"

     Please provide the following information:
-->

#### Why I did it
To reduce the runtime of tests

#### How I did it

Created PR for PTF repository, and added a patch to sonic-buildimage
p4lang/ptf#231
#### How to verify it
Run drop_packets tests in sonic-mgmt.

<!--
If PR needs to be backported, then the PR must be tested against the base branch and the earliest backport release branch and provide tested image version on these two branches. For example, if the PR is requested for master, 202211 and 202012, then the requester needs to provide test results on master and 202012.
-->

#### Which release branch to backport (provide reason below if selected)

<!--
- Note we only backport fixes to a release branch, *not* features!
- Please also provide a reason for the backporting below.
- e.g.
- [x] 202006
-->

- [ ] 202305
- [ ] 202311
- [ ] 202405
- [ ] 202411
- [ ] 202505
- [ ] 202511

#### Tested branch (Please provide the tested image version)

<!--
- Please provide tested image version
- e.g.
- [x] 20201231.100
-->

- [ ] <!-- image version 1 -->
- [ ] <!-- image version 2 -->

#### Description for the changelog
<!--
Write a short (one line) summary that describes the changes in this
pull request for inclusion in the changelog:
-->

<!--
 Ensure to add label/tag for the feature raised. example - PR#2174 under sonic-utilities repo. where, Generic Config and Update feature has been labelled as GCU.
-->

#### Link to config_db schema for YANG module changes
<!--
Provide a link to config_db schema for the table for which YANG model
is defined
Link should point to correct section on https://github.com/Azure/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md
-->

#### A picture of a cute animal (not mandatory but encouraged)
mssonicbld added a commit to sonic-net/sonic-buildimage that referenced this pull request Mar 12, 2026
…5583)

<!--
 Please make sure you've read and understood our contributing guidelines:
 https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md

 failure_prs.log skip_prs.log Make sure all your commits include a signature generated with `git commit -s` **

 If this is a bug fix, make sure your description includes "fixes #xxxx", or
 "closes #xxxx" or "resolves #xxxx"

 Please provide the following information:
-->

#### Why I did it
To reduce the runtime of tests

#### How I did it

Created PR for PTF repository, and added a patch to sonic-buildimage
p4lang/ptf#231
#### How to verify it
Run drop_packets tests in sonic-mgmt.

<!--
If PR needs to be backported, then the PR must be tested against the base branch and the earliest backport release branch and provide tested image version on these two branches. For example, if the PR is requested for master, 202211 and 202012, then the requester needs to provide test results on master and 202012.
-->

#### Which release branch to backport (provide reason below if selected)

<!--
- Note we only backport fixes to a release branch, *not* features!
- Please also provide a reason for the backporting below.
- e.g.
- [x] 202006
-->

- [ ] 202305
- [ ] 202311
- [ ] 202405
- [ ] 202411
- [ ] 202505
- [ ] 202511

#### Tested branch (Please provide the tested image version)

<!--
- Please provide tested image version
- e.g.
- [x] 20201231.100
-->

- [ ] <!-- image version 1 -->
- [ ] <!-- image version 2 -->

#### Description for the changelog
<!--
Write a short (one line) summary that describes the changes in this
pull request for inclusion in the changelog:
-->

<!--
 Ensure to add label/tag for the feature raised. example - PR#2174 under sonic-utilities repo. where, Generic Config and Update feature has been labelled as GCU.
-->

#### Link to config_db schema for YANG module changes
<!--
Provide a link to config_db schema for the table for which YANG model
is defined
Link should point to correct section on https://github.com/Azure/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md
-->

#### A picture of a cute animal (not mandatory but encouraged)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants